<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">

    <Modal :mask-closable="false" title="添加单位" v-model="showhidess" @on-ok="insert">
        <i-form :label-width="80">
            <form-item label="单位名称">
                <i-input v-model="danwei.companyids"></i-input>
            </form-item>
        </i-form>
    </Modal>

    <i-button @click="insertas" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>

    <i-table height="750" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datasasd" :columns="colunmsss" border>
        <template slot="caozuo" slot-scope="{row}">
            <i-button size="small" type="primary" @click="xiugai(row)">修改</i-button>
        </template>
    </i-table>


    <Modal :mask-closable="false" title="修改单位" v-model="showhidessss" @on-ok="update">
        <i-form :label-width="80">
            <form-item label="单位名称">
                <i-input v-model="danwei.companyids"></i-input>
            </form-item>
        </i-form>
    </Modal>

</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datasasd:[],
            showhidessss:false,
            colunmsss:[
                {
                    title:"编号",
                    key:"id"
                },{
                    title:"单位名称",
                    key:"companyids"
                },{
                    title:"操作",
                    slot:"caozuo"
                }
            ],
            danwei:{},
            showhidess:false,
            heights:0,
        },
        methods:{
            insertas(){
                _this.showhidess = true;
            },
            insert(){
                axios.post("/adddanweis",this.danwei).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.danwei = {};
                    _this.select();
                });
            },
            select(){
                axios.get("/selectdanwei").then(({data})=>{
                    _this.datasasd = data.obj;
                })
            },
            xiugai(row){
                console.log(row)
                _this.showhidessss = true;
                Object.assign(this.danwei,row)
            },
            update(){
                axios.post("/updatedanwei",this.danwei).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.danwei = {};
                    _this.select();
                });
            }
        },
        mounted(){
            this.select();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
